#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN TELEPORT version 2

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 31-Dec-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;

using Thn;
using Thn.Application.Logging;
#endregion

namespace Thn.Communication.Teleporting.Logging
{
    /// <summary>
    /// 
    /// </summary>
#if DEBUG
    public
#else
    public
#endif
 class LogInfo
    {
        #region Fields
        #endregion

        #region Properties

        #region Log Type
        private LogType mLogType = LogType.Information;
        /// <summary>
        /// Gets/Sets type of log.
        /// </summary>
        [Savable]
        public LogType LogType
        {
            get { return mLogType; }
            set { mLogType = value; }
        }
        #endregion

        #region Description
        private string mDescription = string.Empty;
        /// <summary>
        /// Gets/Sets Description
        /// </summary>
        [Savable]
        public string Description
        {
            get { return mDescription; }
            set { mDescription = value; }
        }
        #endregion

        #region Time
        private DateTime mTime;
        /// <summary>
        /// Gets/Sets Time
        /// </summary>
        [Savable]
        public DateTime Time
        {
            get { return mTime; }
            set { mTime = value; }
        }
        #endregion

        #region Sender
        private string mSender = "";
        /// <summary>
        /// Gets/Sets name of the sender.
        /// </summary>
        [Savable]
        public string Sender
        {
            get { return mSender; }
            set { mSender = value; }
        }
        #endregion


        #endregion

        #region To Log Event
        /// <summary>
        /// Converts to <see cref="LogEvent"/>.
        /// </summary>
        public LogEvent ToLogEvent()
        {
            LogEvent result = null;

            switch (mLogType)
            {
                #region Information
                case LogType.Information:
                    InformationLog il = new InformationLog(mSender + " : " + mDescription);
                    il.Time = mTime;
                    result = il;
                    break;
                #endregion

                #region Warning
                case LogType.Warning:
                    WarningLog wl = new WarningLog(mSender + " : " + mDescription);
                    wl.Time = mTime;
                    result = wl;
                    break;
                #endregion

                #region Debug
                case LogType.Debug:
                    DebugLog dl = new DebugLog(mSender + " : " + mDescription);
                    dl.Time = mTime;
                    result = dl;
                    break;
                #endregion

                #region Error
                case LogType.Error:
                    Exception ex = new Exception(mSender + " : " + mDescription);
                    ErrorLog el = new ErrorLog(ex);
                    el.Time = mTime;
                    result = el;
                    break;
                #endregion

                #region Unsupported
                default:
                    throw new NotSupportedException();
                    break;
                #endregion
            }

            return result;
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public LogInfo()
        { }

        /// <summary>
        /// Create a new instance from the provided log event.
        /// </summary>
        public LogInfo(LogEvent e, string sender)
        {
            mSender = sender;
            mTime = e.Time;
            mDescription = e.Description;

            if (e is InformationLog) mLogType = LogType.Information;
            else if (e is WarningLog) mLogType = LogType.Warning;
            else if (e is DebugLog) mLogType = LogType.Debug;
            else if (e is ErrorLog) mLogType = LogType.Error;
            else throw new NotSupportedException();
        }
        #endregion
    }
}
